<script setup>
  import { onLoad } from '@dcloudio/uni-app'
  import { KeepAlive, onMounted, ref } from 'vue'
  import { profileAPI, taskReportAPI } from '@/apis/user'
  onMounted(() => {
    getProfileData()
    taskReport()
  })
  // 用户信息
  const userInfo = ref({})
  const getProfileData = async () => {
    const { data } = await profileAPI()
    // console.log(data)
    userInfo.value = data
  }

  //任务数据
  const taskData = ref({})
  //时间 当前月
  const getNowFormatDate = () => {
    //获取当前时间
    let date = new Date()
    let month =
      date.getMonth() + 1 < 10
        ? '0' + (date.getMonth() + 1)
        : date.getMonth() + 1
    let currentdate = {
      year: date.getFullYear().toString(),
      month,
    }
    return currentdate
  }
  const taskReport = async () => {
    const { year, month } = getNowFormatDate()
    const { data } = await taskReportAPI({ year, month })
    taskData.value = data
  }
</script>

<template>
  <view class="page-container">
    <view class="user-profile">
      <image class="avatar" :src="userInfo.avatar" mode=""></image>
      <text class="username">{{ userInfo.name }}</text>
      <text class="no">司机编号：{{ userInfo.number }}</text>
      <text class="mobile">手机号码：{{ userInfo.phone }}</text>
    </view>
    <view class="month-overview">
      <view class="title">本月任务</view>
      <view class="content">
        <view class="item">
          <text class="volumn">{{ taskData.taskAmounts }}</text>
          <text class="label">任务总量</text>
        </view>
        <view class="item">
          <text class="volumn">{{ taskData.completedAmounts }}</text>
          <text class="label">完成任务量</text>
        </view>
        <view class="item">
          <text class="volumn">{{ taskData.transportMileage }}</text>
          <text class="label">运输里程(km)</text>
        </view>
      </view>
    </view>
    <view class="entry-list">
      <uni-list :border="false">
        <uni-list-item
          to="/subpkg_user/truck/index"
          showArrow
          title="车辆信息"
        />
        <uni-list-item
          to="/subpkg_user/task/index"
          showArrow
          title="任务数据"
        />
        <uni-list-item
          to="/subpkg_user/settings/index"
          showArrow
          title="系统设置"
        />
      </uni-list>
    </view>
  </view>
</template>

<style lang="scss" scoped>
  @import './index.scss';
</style>
